package com.tmz.cloudmall.cloudmallorder.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tmz.cloudmall.cloudmallorder.domain.ReturnApply;
import com.tmz.cloudmall.cloudmallorder.service.IReturnApplyService;
import com.tmz.cloudmall.cloudmallcommon.common.annotation.Log;
import com.tmz.cloudmall.cloudmallcommon.common.core.controller.BaseController;
import com.tmz.cloudmall.cloudmallcommon.common.core.domain.AjaxResult;
import com.tmz.cloudmall.cloudmallcommon.common.core.page.TableDataInfo;
import com.tmz.cloudmall.cloudmallcommon.common.enums.BusinessType;
import com.tmz.cloudmall.cloudmallcommon.common.utils.poi.ExcelUtil;

/**
 * 退货申请Controller
 * 
 * @author tmz
 * @date 2025-08-16
 */
@RestController
@RequestMapping("/cloudmallorder/returnApply")
public class ReturnApplyController extends BaseController
{
    @Autowired
    private IReturnApplyService returnApplyService;

    /**
     * 查询退货申请列表
     */
    @PreAuthorize("@ss.hasPermi('cloudmallorder:returnApply:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReturnApply returnApply)
    {
        startPage();
        List<ReturnApply> list = returnApplyService.selectReturnApplyList(returnApply);
        return getDataTable(list);
    }

    /**
     * 导出退货申请列表
     */
    @PreAuthorize("@ss.hasPermi('cloudmallorder:returnApply:export')")
    @Log(title = "退货申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReturnApply returnApply)
    {
        List<ReturnApply> list = returnApplyService.selectReturnApplyList(returnApply);
        ExcelUtil<ReturnApply> util = new ExcelUtil<ReturnApply>(ReturnApply.class);
        util.exportExcel(response, list, "退货申请数据");
    }

    /**
     * 获取退货申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('cloudmallorder:returnApply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(returnApplyService.selectReturnApplyById(id));
    }

    /**
     * 新增退货申请
     */
    @PreAuthorize("@ss.hasPermi('cloudmallorder:returnApply:add')")
    @Log(title = "退货申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReturnApply returnApply)
    {
        return toAjax(returnApplyService.insertReturnApply(returnApply));
    }

    /**
     * 修改退货申请
     */
    @PreAuthorize("@ss.hasPermi('cloudmallorder:returnApply:edit')")
    @Log(title = "退货申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReturnApply returnApply)
    {
        return toAjax(returnApplyService.updateReturnApply(returnApply));
    }

    /**
     * 删除退货申请
     */
    @PreAuthorize("@ss.hasPermi('cloudmallorder:returnApply:remove')")
    @Log(title = "退货申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(returnApplyService.deleteReturnApplyByIds(ids));
    }
}
